define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'books/chapter/index' + location.search,
                    add_url: 'books/chapter/add',
                    edit_url: 'books/chapter/edit',
                    del_url: 'books/chapter/del',
                    multi_url: 'books/chapter/multi',
                    table: 'chapter',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'book_id', title: __('Book_id')},
                        {field: 'book.name', title: __('Book.name'),operate:'LIKE'},
                        {field: 'name', title: __('Name'),operate:false},
                        // {field: 'content_id', title: __('Content_id')},
                        // {field: 'is_vip', title: __('Is_vip')},
                        {field: 'is_free', title: __('是否收费'),
                            searchList: {"0":__('免费'),"1":__('收费')},
                            formatter: Table.api.formatter.normal,operate:false
                        },
                        {field: 'size', title: __('Size'),operate:false},
                        // {field: 'index', title: __('Index')},
                        // {field: 'update', title: __('Update'), operate:'RANGE', addclass:'datetimerange'},
                        // {field: 'book.id', title: __('Book.id')},
                        // {field: 'book.name', title: __('Book.name')},
                        // {field: 'book.cover', title: __('Book.cover')},
                        // {field: 'content.id', title: __('Content.id')},
                        {field: 'operate', title: __('Operate'),
                            table: table, events: Table.api.events.operate,
                           /* buttons:[{
                                name: 'detail',
                                text: __('详情'),
                                // icon: 'fa fa-list',
                                classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                url: 'books/chapter/detail',
                            }],*/
                            formatter: Table.api.formatter.operate

                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});